package com.iafme.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.dto.req.EnterpriseReqDTO;
import com.iafme.dto.res.EnterpriseResDTO;
import com.iafme.mapper.EnterpriseMapper;
import com.iafme.model.Enterprise;
import com.iafme.service.EnterpriseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/19 21:28
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseMapper, Enterprise> implements EnterpriseService {
    @Override
    public Page<EnterpriseResDTO> lists(EnterpriseReqDTO reqDTO) {
        Page<Enterprise> page=new Page<>(reqDTO.getPageNum(),reqDTO.getPageSize());
        LambdaQueryWrapper<Enterprise> like = Wrappers.lambdaQuery(Enterprise.class)
                .like(StrUtil.isNotEmpty(reqDTO.getName()), Enterprise::getName, reqDTO.getName())
                .orderByDesc(Enterprise::getCreateTime);
        return Convert.convert(new TypeReference<Page<EnterpriseResDTO>>() {
        },this.page(page,like));
    }
}
